﻿using FireUI.Themes.WPF.Helper;
using System.Windows;
using System.Windows.Controls;

namespace FireUI.Themes.WPF.Controls;

public class FireIcon : Control
{
    static FireIcon()
    {
        DefaultStyleKeyProperty.OverrideMetadata(
            typeof(FireIcon),
            new FrameworkPropertyMetadata(typeof(FireIcon))
        );
    }

    private static readonly Lazy<IDictionary<FireIconKind, string>> _dataInStance =
        new(FireIconDataFactory.Create());

    #region DependencyProperty:Kind

    public FireIconKind Kind
    {
        get { return (FireIconKind)GetValue(KindProperty); }
        set { SetValue(KindProperty, value); }
    }

    public static readonly DependencyProperty KindProperty = DependencyProperty.Register(
        "Kind",
        typeof(FireIconKind),
        typeof(FireIcon),
        new PropertyMetadata(FireIconKind.None, OnKindPropertyChanged)
    );

    private static void OnKindPropertyChanged(
        DependencyObject d,
        DependencyPropertyChangedEventArgs e
    ) => ((FireIcon)d).UpdateData();

    #endregion DependencyProperty:Kind

    #region DependencyProperty:Data

    public string? Data
    {
        get { return (string?)GetValue(DataProperty); }
        set { SetValue(DataProperty, value); }
    }

    public static readonly DependencyProperty DataProperty = DependencyProperty.Register(
        "Data",
        typeof(string),
        typeof(FireIcon),
        new PropertyMetadata(string.Empty)
    );

    #endregion DependencyProperty:Data

    public override void OnApplyTemplate()
    {
        base.OnApplyTemplate();
    }

    private void UpdateData()
    {
        string? data = null;
        _dataInStance.Value?.TryGetValue(Kind, out data);
        Data = data;
    }
}